<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"
    import="java.sql.*"
    import="java.util.Calendar"
    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>檢查是否為違規會員</title>
</head>
<body>
<% if(session.getAttribute("access") == "y" ){%>
<jsp:useBean id="mydb" scope="page" class="bean.ConDbBean"/> <%//連結資料庫的bean %>
<%
	  String sql="select * from SYS_SETTING WHERE S_NAME='delay_day_deadline'";
	  ResultSet rs_day=mydb.executeQuery(sql);
	  rs_day.next();
      String delay_day = rs_day.getString(3); //取出逾期天數底限
      
      sql="select * from SYS_SETTING WHERE S_NAME='delay_item_deadline'";
	  ResultSet rs_item=mydb.executeQuery(sql);
	  rs_item.next();
      String delay_item = rs_item.getString(3); //取出逾期項目數量底限
      
      sql="select * from SYS_SETTING WHERE S_NAME='damage_freq'";
	  ResultSet rs_dam=mydb.executeQuery(sql);
	  rs_dam.next();
      String dam_freq = rs_dam.getString(3); //取出破壞場地設備次數底限
      
      sql="select * from MEMBER where (DELAY_DAY>="+delay_day+") OR (DELAY_ITEM>="+delay_item+") OR (DAMAGE_PF>="+dam_freq+")";
	  ResultSet rs=mydb.executeQuery(sql);  //找出違規會員
	  while(rs.next()){
	  String num = rs.getString(1);  //將該會員更新為違規會員
	  String sql2="UPDATE MEMBER SET LEVEL_ID='3' WHERE M_NUM='"+num+"'";
      mydb.executeUpdate(sql2);		
	  }
	
response.sendRedirect("../SEARCH/placekeywordsearch.jsp");
%>

<%
  }
  else{
  	response.sendRedirect("../index.jsp"); //若沒有登入則回到index.jsp
  } 
  %>
</body>
</html>